package com.lu.spzx.manager.controller;

import com.github.pagehelper.PageInfo;
import com.lu.spzx.log.annotation.Log;
import com.lu.spzx.manager.service.BrandService;
import com.lu.spzx.model.entity.product.Brand;
import com.lu.spzx.model.vo.common.Result;
import com.lu.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/admin/product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @GetMapping("/{page}/{limit}")
    // 添加 Log 注解,设置属性
    @Log(title = "品牌模块-查询方法", businessType = 0)
    public Result<PageInfo<Brand>> findByPage(@PathVariable Integer page, @PathVariable Integer limit) {
        PageInfo<Brand> pageInfo = this.brandService.findByPage(page, limit);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("save")
    public Result save(@RequestBody Brand brand) {
        this.brandService.save(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @PutMapping("updateById")
    public Result updateById(@RequestBody Brand brand) {
        this.brandService.updateById(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id) {
        this.brandService.deleteById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/findAll")
    public Result findAll() {
        List<Brand> list = this.brandService.findAll();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

}